
// import TableList from "@components/templates/tablelist";
import TableList from "@components/templates/customtablelist";
import { HttpBillList, HttpBillSummary } from '@/service/api/views'
import { mapState,mapGetters } from "vuex";
// import compAdd from './add';
export default {
    mixins: [TableList],
    components: {
        // compAdd,
    },
    data() {
        return {
            // totals: 0,
            isMixin: true,
            Tools: {show: true},
            Tabs: {show: true},
            formData:{
                search:{
                }
            },
            Searchs: {
                show: true,
                labelWidth: 120,
            },
            Plugins: {show: true},
            
            totalnum:'',
        }
    },
    methods: {
        ajaxRequest: HttpBillList,
        interceptRequest(params){
            if(params.search.BT_createdAt&&params.search.BT_createdAt[0]!=''){
                params.search.BT_createdAt = this.handleDateFormat(params.search.BT_createdAt[0],'yyyy-mm-dd') + ' ~ ' +this.handleDateFormat(params.search.BT_createdAt[1],'yyyy-mm-dd')
            }
            
            HttpBillSummary({...params}).then(res=>{
                this.totalnum = res.data
            })
            return params
        },
        toolsRender() { //自定义工具行
            return (
                <div style="background: #fff;margin-bottom: 10px;padding: 5px;padding-left: 10px;">
                    <span class="color-success">扣减总额:{this.totalnum.totalDeduction}</span>
                    <span class="color-error margin-left-20">返还总额:{this.totalnum.totalReturn}</span>
                </div>
            ) 
        },
        handleOperates(params="", type,batch) {
            if(batch===true){
                params=(params||this.checkedData.join(','))+'';
                if(!params.length) return this.$Message.warning('请选择至少一条数据');
            }
            switch (type) {
                case 'add':
                    var url = this.$router.resolve({
                        name: "adjustmentAdd",
                    });
                    window.open(url.href, '_blank');
                    break;
                case 'download':
                    this.handleWebfs(
                        process.env.VUE_APP_APIURL_SHIP + "/api/jwt/spl/adjustment/export",{},
                        "download"
                    );
                    break;
                
            }
        },
    },
    computed: {
        ...mapGetters('dictionary',['getSysAllList']),
        TabsData(){
            return [
                {
                    name: this.$ct('global.common.all',{defaultValue:'全部'}),
                    key:'EQ_type',
                    val: null
                }, {
                    name: '调账扣减',
                    key:'EQ_type',
                    val: "0"
                }, {
                    name: '调账返还',
                    key:'EQ_type',
                    val: "1"
                }
            ]
        },
        // 搜索下拉框展示内容
        SearchsData() {
            return  [
                {
                    label: '组织',
                    tag: 'Select',
                    key: 'EQ_organizationId',
                    options:this.getSysAllList,
                    props:{
                        filterable:true,
                    },
                    show:true,
                },
                {
                    label: '运单号',
                    tag: 'Input',
                    key: 'EQ_trackingNo',
                    show:true,
                },
                {
                    label: '账单编号',
                    tag: 'Input',
                    key: 'EQ_billNo',
                    show:true,
                },
                {
                    label: '创建时间',
                    tag: 'DatePicker',
                    key: 'BT_createdAt',
                    props:{
                        type:'daterange',
                        options:this.options,
                    },
                    // hideSearchTip:true,
                    style: "width:200px",
                },
            ]
        },
        ToolsData(){
            return [
                {
                    name: "添加",
                    theme: 'primary',
                    operate: 'add',
                },
                {
                    name: "导出",
                    theme: 'success',
                    operate: 'download',
                },
            ]
        },
        // table的展示数据
        columns() {
            return [{
                title: "创建时间",
                key: "createdAt",
                sortable: true,
            }, {
                title: "账户组织",
                key: "organizationName",
            }, {
                title: "类型",
                key: "type",
                sortable: true,
                render(h, { row }) {
                    return <span>{row.type == 0 ? '调账扣减' : '调账返还'}</span>
                }
            }, {
                title: "调整月份",
                key: "month",
                sortable: true,
                render(h, { row }) {
                    return <span>{(row.month || "").substr(0, 7)}</span>
                }
            }, {
                title: "运单号",
                key: "trackingNo",
                sortable: true,
            }, {
                title: "账单编号",
                key: "billNo",
                sortable: true,
            }, {
                title: "调整金额（USD）",
                key: "amount",
            }, {
                title: "账户可用余额（USD）",
                key: "availableAmount",
            }, {
                title: "备注",
                key: "remark",
            }, {
                title: "创建人",
                key: "createdName",
            },];
        },
        
    },

};
